﻿using QQMusic.API;
using QQMusic.Helper;
using QQMusic.Model;
using QQMusic.View;
using QQMusic.ViewModel.Base;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace QQMusic.ViewModel
{
    public class HomePageViewModel : ViewModelBase
    {
        public HomePageViewModel()
        {
        }

        #region 事件

        /// <summary>
        /// 鼠标进入
        /// </summary>
        public ICommand OnMouseEnterCommand => new DelegateCommand((sender) =>
        {
            if (sender is Grid grid)
            {
                List<Button> buttons = VisualHelper.GetChildList<Button>(grid);
                foreach (Button button in buttons)
                {
                    button.Visibility = Visibility.Visible;
                }
            }
        });

        /// <summary>
        /// 鼠标离开
        /// </summary>
        public ICommand OnMouseLeaveCommand => new DelegateCommand((sender) =>
        {
            if (sender is Grid grid)
            {
                List<Button> buttons = VisualHelper.GetChildList<Button>(grid);
                foreach (Button button in buttons)
                {
                    button.Visibility = Visibility.Hidden;
                }
            }
        });

        /// <summary>
        /// 页面大小改变
        /// </summary>
        public ICommand OnSizeChangedCommand => new DelegateCommand((sender) =>
        {
            if (sender is HomePage page)
            {
                if (page.ActualWidth > 1155)
                {
                    OfficalMtypes = Arrays.Copy<ObservableCollection<MusicType>, MusicType>(officals, 0, 6);
                    RadiosMtypes = Arrays.Copy<ObservableCollection<MusicType>, MusicType>(radios, 0, 6);
                    VideosMtypes = Arrays.Copy<ObservableCollection<MusicType>, MusicType>(videos, 0, 5);
                }
                else if (page.ActualWidth > 985)
                {
                    OfficalMtypes = Arrays.Copy<ObservableCollection<MusicType>, MusicType>(officals, 0, 5);
                    RadiosMtypes = Arrays.Copy<ObservableCollection<MusicType>, MusicType>(radios, 0, 5);
                    VideosMtypes = Arrays.Copy<ObservableCollection<MusicType>, MusicType>(videos, 0, 4);
                }
                else
                {
                    OfficalMtypes = Arrays.Copy<ObservableCollection<MusicType>, MusicType>(officals, 0, 4);
                    RadiosMtypes = Arrays.Copy<ObservableCollection<MusicType>, MusicType>(radios, 0, 4);
                    VideosMtypes = Arrays.Copy<ObservableCollection<MusicType>, MusicType>(videos, 0, 3);
                }
                OfficalCount = officalMtypes.Count;
                RadiosCount = radiosMtypes.Count;
                VideosCount = videosMtypes.Count;
            }
        });

        #endregion

        #region 属性

        public List<string> bitmapImages = new List<string>()
        {
            "/Image/background1.jpg",
            "/Image/background2.jpg",
            "/Image/background3.jpg",
            "/Image/background4.jpg",
            "/Image/background5.jpg",
        };

        public List<string> BitmapImages
        {
            get => bitmapImages;
            set
            {
                bitmapImages = value;
                OnPropertyChanged(nameof(BitmapImages));
            }
        }

        private int officalCount = 4;

        public int OfficalCount
        {
            get { return officalCount; }
            set
            {
                officalCount = value;
                OnPropertyChanged(nameof(OfficalCount));
            }
        }

        private ObservableCollection<MusicType> officals = new ObservableCollection<MusicType>()
        {
            new MusicType(){ ImagePath="/Image/background1.jpg", Musics="刚刚更新", Title="今日私享" },
            new MusicType(){ ImagePath="/Image/background2.jpg", Musics="120万", Title="华语|心情匣子" },
            new MusicType(){ ImagePath="/Image/background3.jpg", Musics="129万", Title="欧美电音|梦想启航" },
            new MusicType(){ ImagePath="/Image/background4.jpg", Musics="210万", Title="华语|治愈系女生" },
            new MusicType(){ ImagePath="/Image/background5.jpg", Musics="129万", Title="欧美电音|梦想启航" },
            new MusicType(){ ImagePath="/Image/background6.jpg", Musics="210万", Title="华语|治愈系女生" },
        };

        /// <summary>
        /// 官方歌单
        /// </summary>
        private ObservableCollection<MusicType> officalMtypes = new ObservableCollection<MusicType>()
        {
            new MusicType(){ ImagePath="/Image/background1.jpg", Musics="刚刚更新", Title="今日私享" },
            new MusicType(){ ImagePath="/Image/background2.jpg", Musics="120万", Title="华语|心情匣子" },
            new MusicType(){ ImagePath="/Image/background3.jpg", Musics="129万", Title="欧美电音|梦想启航" },
            new MusicType(){ ImagePath="/Image/background4.jpg", Musics="210万", Title="华语|治愈系女生" },
        };

        public ObservableCollection<MusicType> OfficalMtypes
        {
            get => officalMtypes;
            set
            {
                officalMtypes = value;
                OnPropertyChanged(nameof(OfficalMtypes));
            }
        }

        public int RadiosCount
        {
            get { return officalCount; }
            set
            {
                officalCount = value;
                OnPropertyChanged(nameof(RadiosCount));
            }
        }

        private ObservableCollection<MusicType> radios = new ObservableCollection<MusicType>()
        {
            new MusicType(){ ImagePath="/Image/background1.jpg", Musics="10万", Title="深夜治愈所" },
            new MusicType(){ ImagePath="/Image/background2.jpg", Musics="12万", Title="澄西微露电台" },
            new MusicType(){ ImagePath="/Image/background3.jpg", Musics="19万", Title="幼清电台" },
            new MusicType(){ ImagePath="/Image/background4.jpg", Musics="20万", Title="逆天小王妃" },
            new MusicType(){ ImagePath="/Image/background5.jpg", Musics="19万", Title="幼清电台" },
            new MusicType(){ ImagePath="/Image/background6.jpg", Musics="20万", Title="逆天小王妃" },
        };

        /// <summary>
        /// 推荐电台
        /// </summary>
        private ObservableCollection<MusicType> radiosMtypes = new ObservableCollection<MusicType>()
        {
            new MusicType(){ ImagePath="/Image/background1.jpg", Musics="10万", Title="深夜治愈所" },
            new MusicType(){ ImagePath="/Image/background2.jpg", Musics="12万", Title="澄西微露电台" },
            new MusicType(){ ImagePath="/Image/background3.jpg", Musics="19万", Title="幼清电台" },
            new MusicType(){ ImagePath="/Image/background4.jpg", Musics="20万", Title="逆天小王妃" },
        };

        public ObservableCollection<MusicType> RadiosMtypes
        {
            get => radiosMtypes;
            set
            {
                radiosMtypes = value;
                OnPropertyChanged(nameof(RadiosMtypes));
            }
        }

        private int videoCount = 3;

        public int VideosCount
        {
            get { return videoCount; }
            set
            {
                videoCount = value;
                OnPropertyChanged(nameof(VideosCount));
            }
        }

        private ObservableCollection<MusicType> videos = new ObservableCollection<MusicType>()
        {
            new MusicType(){ ImagePath="/Image/background1.jpg", Musics="18万", Title="不分手的恋爱", SubTitle="汪苏泷" },
            new MusicType(){ ImagePath="/Image/background2.jpg", Musics="16万", Title="后会无期", SubTitle="徐良" },
            new MusicType(){ ImagePath="/Image/background3.jpg", Musics="12万", Title="不想和你做朋友", SubTitle="小贱" },
            new MusicType(){ ImagePath="/Image/background4.jpg", Musics = "72万", Title = "有何不可", SubTitle="许嵩" },
            new MusicType(){ ImagePath="/Image/background5.jpg", Musics="12万", Title="东风破", SubTitle="周杰伦" }
        };

        /// <summary>
        /// 推荐视频
        /// </summary>
        private ObservableCollection<MusicType> videosMtypes = new ObservableCollection<MusicType>()
        {
            new MusicType(){ ImagePath="/Image/background1.jpg", Musics="18万", Title="不分手的恋爱", SubTitle="汪苏泷" },
            new MusicType(){ ImagePath="/Image/background2.jpg", Musics="16万", Title="后会无期", SubTitle="徐良" },
            new MusicType(){ ImagePath="/Image/background3.jpg", Musics="12万", Title="不想和你做朋友", SubTitle="小贱" },
        };

        public ObservableCollection<MusicType> VideosMtypes
        {
            get => videosMtypes;
            set
            {
                videosMtypes = value;
                OnPropertyChanged(nameof(VideosMtypes));
            }
        }
        #endregion
    }
}
